import { createApp } from 'vue'
import renderTarget from './renderTarget.vue'

function mount(options) {
  // 创建一个节点，并将组件挂载上去
  const el = document.createElement('div')
  document.body.appendChild(el)

  const app = createApp(renderTarget, {
    ...options,
    // 不再需要时候 需调用remove函数 卸载元素
    remove() {
      app.unmount(el)
      document.body.removeChild(el)
    },
  })
  return app.mount(el)
}

export default function (app) {
  app.config.globalProperties[`$dialog`] = mount
}
